package com.cskaoyan.wx.controller;

import com.cskaoyan.bean.User;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.wx.bean.bo.WxCartAddBo;
import com.cskaoyan.wx.bean.bo.WxCartCheckBo;
import com.cskaoyan.wx.bean.bo.WxCartDeleteBo;
import com.cskaoyan.wx.bean.bo.WxCartUpdateBo;
import com.cskaoyan.wx.bean.vo.WxCartCheckoutVo;
import com.cskaoyan.wx.bean.vo.WxCartIndexVo;
import com.cskaoyan.wx.service.WxCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("wx/cart")
public class WxCartController {

    @Autowired
    WxCartService wxCartService;

    /**
     * 功能:购物车页面,/index
     * 作者:whj
     */
    @RequestMapping("index")
    public BaseRespVo index(){
        WxCartIndexVo wxCartIndexVo = wxCartService.query();
        return BaseRespVo.ok(wxCartIndexVo);
    }

    /**
     * 功能:购物车页面,/checked
     * 作者:whj
     */
    @RequestMapping("checked")
    public BaseRespVo checked(@RequestBody WxCartCheckBo wxCartCheckBo){
        WxCartIndexVo wxCartIndexVo = wxCartService.checked(wxCartCheckBo);
        if(wxCartIndexVo == null){
            return BaseRespVo.error("操作失败!");
        }
        return BaseRespVo.ok(wxCartIndexVo);
    }

    /**
     * 功能:购物车页面,/update
     * 作者:whj
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody WxCartUpdateBo wxCartUpdateBo){
        int code = wxCartService.update(wxCartUpdateBo);
        if(code == 404){
            return BaseRespVo.error("操作失败!");
        }
        return BaseRespVo.ok();
    }

    /**
     * 功能:购物车页面,/delete
     * 作者:whj
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody WxCartDeleteBo wxCartDeleteBo){
        WxCartIndexVo wxCartIndexVo = wxCartService.delete(wxCartDeleteBo);
        if(wxCartIndexVo == null){
            return BaseRespVo.error("操作失败!");
        }
        return BaseRespVo.ok(wxCartIndexVo);
    }

    /**
     * 功能:购物车页面,/checkout
     * 作者:whj
     */
    @RequestMapping("checkout")
    public BaseRespVo checkout(Integer cartId,Integer addressId,Integer couponId,Integer grouponRulesId){
        WxCartCheckoutVo wxCartCheckoutVo = wxCartService.checkout(cartId,addressId,couponId,grouponRulesId);
        if(wxCartCheckoutVo == null){
            return BaseRespVo.error("操作失败!");
        }
        return BaseRespVo.ok(wxCartCheckoutVo);
    }

    /**
     * 功能:加入购物车,/add
     * 作者:whj
     */
    @RequestMapping("add")
    public BaseRespVo add(@RequestBody WxCartAddBo wxCartAddBo){
        int code = wxCartService.add(wxCartAddBo);
        if(code == -1){
            return BaseRespVo.error("操作失败!");
        }
        return BaseRespVo.ok(code);
    }

    /**
     * 功能:购物车商品数量,/goodscount
     * 作者:whj
     */
    @RequestMapping("goodscount")
    public BaseRespVo goodscount(){
        int code = wxCartService.goodscount();
        if(code == -1){
            return BaseRespVo.error("操作失败!");
        }
        return BaseRespVo.ok(code);
    }

    /**
     * 功能:购物车商品数量,/fastadd
     * 作者:whj
     */
    @RequestMapping("fastadd")
    public BaseRespVo fastadd(@RequestBody WxCartAddBo wxCartAddBo){
        int code = wxCartService.fastadd(wxCartAddBo);
        if(code == -1){
            return BaseRespVo.error("操作失败!");
        }
        return BaseRespVo.ok(228);
    }
}
